local skel = fk.CreateSkill {
  name = "lb__fengjie",
}

Fk:loadTranslationTable {
  ["lb__fengjie"] = "风界",
  [":lb__fengjie"] = "当你使用伤害牌时，你可以执行第X项（X为你本轮使用过的伤害牌数）：<br>" ..
      "1.此牌不可被响应；<br>" ..
      "2.摸两张牌；<br>" ..
      --"3.失去〖风界〗并使用弃牌堆中的一张武器牌，此牌无法被其他角色移动。",
      "3.使用弃牌堆中的一张武器牌并移除此项，此牌无法被其他角色移动。",

  ["#lb__fengjie_1"] = "风界：你可以令 %arg 不可被响应",
  ["#lb__fengjie_2"] = "风界：你可以摸两张牌",
  ["#lb__fengjie_3"] = "风界：你可以使用弃牌堆中的一张武器牌，此牌无法被其他角色移动",

  ["@lb__fengjie"] = "风界",

  ["$lb__fengjie1"] = "飞舞吧，风暴！",
  ["$lb__fengjie2"] = "是时候做个了结了。",
}

skel:addEffect(fk.CardUsing, {
  mute = true,
  can_trigger = function(self, event, target, player, data)
    if player:hasSkill(skel.name) and target == player and data.card.is_damage_card then
      local logic = player.room.logic
      local n = #logic:getEventsOfScope(GameEvent.UseCard, 4, function(e)
        local use = e.data
        return use.from == player and use.card.is_damage_card
      end, Player.HistoryRound)
      if n < 4 then
        event:setCostData(self, { n = n })
        return true
      end
    end
  end,
  on_cost = function(self, event, target, player, data)
    local room = player.room
    local n = event:getCostData(self).n
    local prompt = "#lb__fengjie_2"
    if n == 1 then
      prompt = "#lb__fengjie_1:::" .. data.card:toLogString()
    end
    if n == 3 then
      if player.sealedSlots[Player.WeaponSlot] == nil and player:getMark(skel.name) == 0 then
        local ids = table.filter(room.discard_pile, function(id)
          return Fk:getCardById(id).sub_type == Card.SubtypeWeapon
        end)
        if #ids == 0 then return end
        local use = room:askToUseRealCard(player, {
          min_num = 1,
          max_num = 1,
          skill_name = skel.name,
          expand_pile = ids,
          pattern = tostring(Exppattern { id = ids }),
          cancelable = true,
          prompt = "#lb__fengjie_3",
          skip = true
        })
        event:setCostData(self, { n = n, use = use })
        return use
      end
    else
      return room:askToSkillInvoke(player, { skill_name = skel.name, prompt = prompt })
    end
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    local cost = event:getCostData(self)
    local n = cost.n
    player:broadcastSkillInvoke(skel.name)
    if n == 1 then
      data.disresponsiveList = room.players
      room:notifySkillInvoked(player, skel.name, "offensive")
    elseif n == 2 then
      player:drawCards(2, skel.name)
      room:notifySkillInvoked(player, skel.name, "drawcard")
    elseif n == 3 then
      room:notifySkillInvoked(player, skel.name, "special")
      room:setPlayerMark(player, skel.name, 1)
      local card = Fk:getCardById(event:getCostData(self).use.card.id)
      room:useCard(event:getCostData(self).use)
      if not table.contains(player:getCardIds("e"), card.id) then return end
      room:setPlayerMark(player, "@lb__fengjie", Fk:translate(card.name))
      room:setCardMark(card, "#ProhibitMove-inhand", { skel.name, player.id, "@lb__fengjie" })
    end
  end,
})

skel:addLoseEffect(function (self, player, is_death)
  player.room:setPlayerMark(player, skel.name, 0) -- 第3项
end)

return skel